package com.lh.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lh.commonutils.R;
import com.lh.entity.TOrder;
import com.lh.service.ITOrderService;
import com.lh.servicebase.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author lh
 * @since 2021-06-16
 */
@RestController
@RequestMapping("/order")
public class TOrderController {


    @Autowired
    private ITOrderService orderService;

    @PostMapping("createOrder/{courseId}")
    public R saveOrder(@PathVariable String courseId, HttpServletRequest request){

//        创建订单，返回订单号
         String  orderNo = orderService.creatOrders(courseId, JwtUtils.getMemberIdByJwtToken(request));

        return R.ok().data("orderId",orderNo);
    }
//根据订单id查询点订单信息
    @GetMapping("getOrderInfo/{orderId}")
    public  R getOrderInfo(@PathVariable String orderId){
        QueryWrapper<TOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no",orderId);
        TOrder one = orderService.getOne(wrapper);

        return  R.ok().data("item",one);


    }

}

